<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片懒加载</title>
</head>
<style>
    *{
        margin: 0;padding: 0;
    }
    img{
        width: 300px;
        height: 400px;
    }
</style>


<h1>日期格式化</h1>
<script src="./utils.js"></script>
<script>
    console.log(dateFormat('2021-7-26 11:29:21'));
</script>




<h1>判断浏览器内核类型</h1>
<script src="./utils.js"></script>
<script>
    console.log(num)
</script>





<h1>判断是不是移动端</h1>
<script src="./utils.js"></script>

<h1>判断是不是微信浏览器</h1>
<script src="./utils.js"></script>
<body>
    <img datasrc="https://tse1-mm.cn.bing.net/th/id/R-C.a4ff6b97d60d6cbda74657b0dcdffc91?rik=%2fQ98UwemqcRJvw&riu=http%3a%2f%2fs2.doyo.cn%2fimg%2f59%2fdd%2fcc789e9e78751000001e.jpg&ehk=tq8gqXPPa%2f5stE7d2P09nB8J4PNRQ8%2fODn0Qs%2f3qz%2bI%3d&risl=&pid=ImgRaw&r=0"  src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt=""><br>
    <img datasrc="https://tse1-mm.cn.bing.net/th/id/OIP-C.idjspMahH4SI1jS-9sTIVwHaKi?w=204&h=291&c=7&r=0&o=5&pid=1.7" src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt=""><br>
    <img datasrc="https://tse1-mm.cn.bing.net/th/id/OIP-C.I42XesPdnNg6Wc3sZxLkwwHaKi?w=204&h=291&c=7&r=0&o=5&pid=1.7" src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt=""><br>
    <img datasrc="https://tse2-mm.cn.bing.net/th/id/OIP-C.tDSubUhGFtHCjLcjeK7LkgHaKt?w=204&h=296&c=7&r=0&o=5&pid=1.7" src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt=""><br>
    <img datasrc="https://tse3-mm.cn.bing.net/th/id/OIP-C.QIHQBB46R7gr-PMYz3WfwwHaKt?w=204&h=296&c=7&r=0&o=5&pid=1.7" src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt=""><br>
    <img datasrc="https://tse4-mm.cn.bing.net/th/id/OIP-C.TlKlP51WBx-3_NaXnmddzgHaQO?w=159&h=350&c=7&r=0&o=5&pid=1.7" src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt=""><br>
    <img datasrc="https://tse4-mm.cn.bing.net/th/id/OIP-C.szKVWbAcTThfOinHqFcWiQHaLH?w=204&h=306&c=7&r=0&o=5&pid=1.7" src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt=""><br>
    <img datasrc="https://tse1-mm.cn.bing.net/th/id/OIP-C.ACYlpfLI5mCv9zyRnrUvoQHaNK?w=187&h=333&c=7&r=0&o=5&pid=1.7" src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt=""><br>
    <img datasrc="https://tse2-mm.cn.bing.net/th/id/OIP-C._93_19-OZJgf-1mh7TGegAHaIn?w=204&h=238&c=7&r=0&o=5&pid=1.7" src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt=""><br>
    <img datasrc="https://tse3-mm.cn.bing.net/th/id/OIP-C.5h0XVEK3oUPIDg-FaEFLhAHaJQ?w=204&h=255&c=7&r=0&o=5&pid=1.7" src="https://tse1-mm.cn.bing.net/th/id/R-C.5b1fe33d1621848930b98b0783ed56c9?rik=wRyiKekmJSoa9Q&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f02%2fLoading-GIF-Image-14.gif&ehk=TB%2bK%2fRRl4r%2f2egaI2ENfMPXLoG6qL5ULgLgP859fsZA%3d&risl=&pid=ImgRaw&r=0" alt="">
</body>

</html>

<script>
    var imgs = document.querySelectorAll('img')
    function lazyload(){
        var temp1 = document.documentElement.clientHeight||document.body.clientHeight
        var temp2 = document.documentElement.scrollTop||document.body.scrollTop
        var a12 = temp1 + temp2
        imgs.forEach(item=>{
            if(item.offsetTop < a12){
                item.src=item.getAttribute('datasrc')
            }
        })
    }
    lazyload()
    window.onscroll=lazyload 
</script>